<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('渠道信息列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <li>
                            <label>渠道编号：</label>
                            <input type="text" name="channelCode2"/>
                        </li>

                        <li>
                            <label>渠道名称：</label>
                            <select name="channelCode" class="form-control">
                                <option value="">所有</option>
                                <option th:each="item:${channelInfoList}" th:text="${item.name}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>

                        <li>
                            <label>渠道类型：</label>
                            <select name="channelType" class="form-control">
                                <option value="">所有</option>
                                <option th:each="item:${channelTypeList}" th:text="${item.name}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>

                        <li>
                            <label>渠道商务：</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="ownerId">
                                    <option value="">所有</option>
                                    <option th:each="item:${managerInfoList}" th:value="${item.userId}"
                                            th:text="${item.username}"></option>
                                </select>
                            </div>
                        </li>


                        <li>
                            <label>流量类型：</label>
                            <select name="appType" class="form-control">
                                <option value="">所有</option>
                                <option th:each="item:${flowRateTypeList}" th:text="${item.name}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>

                        <li>
                            <label>应用类型：</label>
                            <select name="appType" class="form-control">
                                <option value="">所有</option>
                                <option th:each="item:${appTypeList}" th:text="${item.name}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>

                        <li>
                            <label>计费类型：</label>
                            <select name="chargeType" class="form-control">
                                <option value="">所有</option>
                                <option value="1">UV结算</option>
                                <option value="2">注册结算</option>
                                <option value="3">联登结算</option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="extend:channel:add">
                <i class="fa fa-plus"></i> 添加
            </a>

            <a class="btn btn-success" onclick="managerInfoList();" shiro:hasPermission="extend:channel:managerList">
                <i class="fa fa-plus"></i> 渠道商务
            </a>
            <!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="extend:channel:remove">-->
            <!--                    <i class="fa fa-remove"></i> 删除-->
            <!--                </a>-->
            <!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="extend:channel:export">-->
            <!--                    <i class="fa fa-download"></i> 导出-->
            <!--                </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('extend:channel:edit')}]];
    var editMainFlag = [[${@permission.hasPermi('extend:channel:editMain')}]];
    var removeFlag = [[${@permission.hasPermi('extend:channel:remove')}]];
    var prefix = ctx + "extend/channel";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "渠道信息",
            striped: true,
            columns: [
                {
                    field: 'channelName',
                    title: '渠道名称（编号）',
                    formatter: function (value, row, index) {
                        return row.channelName + ' [ ' + row.channelCode + ' ]';
                    }
                },
                {
                    field: 'channelType',
                    title: '渠道类型',
                    formatter: function (value, row, index) {
                        var reuslt = row.channelTypeStr;
                        if (row.channelType == 'DC') {
                            reuslt = '<span style="color: #1c84c6">' + row.channelTypeStr + '</span>';
                        } else if (row.channelType == 'ZD') {
                            reuslt = '<span style="color: #f3124e">' + row.channelTypeStr + '</span>';
                        }
                        return reuslt;
                    }
                },
                {
                    field: 'chargeAmount',
                    title: '价格（比率）',
                    formatter: function (value, row, index) {
                        return row.chargeAmount + ' [ ' + row.channelRate + ' ]';
                    }
                },
                // {
                //     field: 'channelRate',
                //     title: '渠道比率'
                // },
                // {
                //     field: 'owner',
                //     title: '渠道主'
                // },

                {
                    field: 'chargeType',
                    title: '计费类型',
                    formatter: function (value, row, index) {
                        var result = 'UV计价';
                        if (row.chargeType == 2) {
                            result = '注册计价';
                        } else if (row.chargeType == 3) {
                            result = '联登计价';
                        }
                        return result;
                    }
                },
                // {
                //     field: 'unionFlag',
                //     title: '是否联登渠道',
                //     formatter: function (value,row,index){
                //         return row.unionFlag==1?'<span class="badge badge-primary">是</span>':'<span class="badge badge-danger">否</span>';
                //     }
                // },
                {
                    field: 'pageTypeName',
                    title: '推广页类型'
                },
                {
                    field: 'flowRateTypeStr',
                    title: '流量类型'
                },
                {
                    // field: 'extUrl',
                    title: '推广链接',
                    formatter: function (value, row, index) {
                        return '<a target="_blank" href="' + row.extUrl + '">' + row.extUrl + '</a>';
                    }
                },
                {
                    field: 'appName',
                    title: '应用名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'smsVerifyFlag',
                    title: '是否短信验证',
                    formatter: function (value, row, index) {
                        return statusToolsSms(row);
                    }
                },
                {
                    field: 'adminAccount',
                    title: 'A信息',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == '') {
                            return '-';
                        }
                        return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showAdminInfo(\'' + row.adminAccount + '\',\'' + row.adminPasswd + '\')">展示</span>'
                    }
                },
                {
                    field: 'adminPasswd',
                    title: '商务',
                    formatter: function (value, row, index) {
                        var result = '';
                        if (row.ownerName != undefined) {
                            result = result + '商务：' + row.ownerName
                        }
                        if (row.ownerName != undefined && row.creatorName != undefined) {
                            result = result + '<br>'
                        }
                        if (row.creatorName != undefined) {
                            result = result + '创建：' + row.creatorName
                        }
                        return result;
                    }
                },
                // {
                //     field: 'notIncludeProduct',
                //     title: '不包括的产品'
                // },
                //     {
                //         field: 'notIncludeSource',
                //         title: '不包括的来源'
                //     },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.channelCode + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editMainFlag + '" href="javascript:void(0)" onclick="editMainFun(\'' + row.channelCode + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.channelCode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.channelCode + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.channelCode + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(channelCode) {
        $.modal.confirm("确认要停用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"channelCode": channelCode, "status": 0});
        })
    }

    /* 用户管理启用 */
    function enable(channelCode) {
        $.modal.confirm("确认要启用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"channelCode": channelCode, "status": 1});
        })
    }


    /*******短信验证*********/
    /* 用户状态显示 */
    function statusToolsSms(row) {
        if (row.smsVerifyFlag == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableSms(\'' + row.channelCode + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableSms(\'' + row.channelCode + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disableSms(channelCode) {
        $.modal.confirm("确认要关闭短信验证吗？", function () {
            $.operate.post(prefix + "/changeSmsFlag", {"channelCode": channelCode, "smsVerifyFlag": 0});
        })
    }

    /* 用户管理启用 */
    function enableSms(channelCode) {
        $.modal.confirm("确认要打开短信验证吗？", function () {
            $.operate.post(prefix + "/changeSmsFlag", {"channelCode": channelCode, "smsVerifyFlag": 1});
        })
    }

    /**
     * 展示账号信息
     * @param adminAccount
     * @param adminPwd
     */
    function showAdminInfo(adminAccount, adminPwd) {
        var content = '账号：' + adminAccount +
            '<br>密码：' + adminPwd +
            '<br>登陆地址：https://admin.goldenblossom.cn'
        $.modal.alert(content, modal_status.MESSAGE, '注册渠道登陆信息');
    }

    function editMainFun(channelCode) {
        var url = prefix + "/editMain/" + channelCode;
        $.modal.open('修改渠道信息', url);
    }

    function managerInfoList() {
        var url = ctx + 'special/managerInfo/2';
        $.modal.openTab('渠道商务', url);
    }

</script>
</body>
</html>